<?php
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tucao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/taobao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tuijian/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/config/city_config.php");

//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival["p"], "p", "");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	if($g_cgival["p"] < 1) $g_cgival["p"]=1;

	
	cgi::both($g_cgival["tag_id"], "tag_id", "");
	$g_cgival["tag_id"] = intval($g_cgival["tag_id"]);
	
	cgi::both($g_cgival["show_type"], "show_type", "");
	$g_cgival["show_type"] = intval($g_cgival["show_type"]);
	
	cgi::both($g_cgival["id"], "id", "");
	$g_cgival["id"] = intval($g_cgival["id"]);
}


function get_data()
{
	
	global $g_cgival, $g_pro, $g_show, $config;
	$g_show["id"] = $id = $g_cgival["id"] ;
	$g_show["main_domain"] = "http://".$config["main_domain"];
	

	
	$start_year = "2013";
	$get_weeks = ceil((time()-strtotime("$start_year-01-01"))/(86400*7));
	if($id > $get_weeks)
	{
		throw new Exception("数据异常！");
	}
	
	
	
	//登录相关
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	
	if($is_login)
	{
		$user_detail_info = $user_info->get_cur_user_info();
	
		$uid = $user_detail_info["uid"];
		$user_nickname = $user_detail_info["user_nickname"];
		$g_show["is_logined"] = true;
		$g_show["current_user_info"] = $user_detail_info;
		$config["show_pubu"] = true;
	}
	//登录
	
	
	//关键字
	$db_mblog_cron_topic_tag = new db_mblog_cron_topic_tag();
	$current_site_name = $config["current_site_name"];
	$g_show["page_keywords"]  = "{$current_site_name},{$current_site_name}图片,{$current_site_name}视频,{$current_site_name}组队,{$current_site_name}玩家,一起玩{$current_site_name},玩{$current_site_name},玩{$current_site_name}的人";
	$g_show["page_desc"]  = "{$current_site_name}玩家分享的游戏美图,{$current_site_name}玩家聚集地";
	$g_show["page_title"] = "{$current_site_name}美图_游戏美图";
	$g_show["page_desc"]  .=  "_最有意思的游戏玩家分享平台";	
	//关键字
	
	//导航配置
	$daohang[] = "<a href='/mblog/'>图库</a>";
	if($current_tag_info["tag_name"])
	{
		$daohang[] = $current_tag_info["tag_name"];
	}
	else
	{
		$daohang[] = "首页";
	}
	$g_show["daohang"] =join(" <i>&gt;</i> ",$daohang);
	//导航配置

	//取数据
	$db_tuijian_daren = new db_tuijian_daren();
	$g_show["tuijian_user_info"] = $db_tuijian_daren->get_item_by_id($id);
	
	$g_show["tuijian_user_detail"] = unserialize($g_show["tuijian_user_info"]["detail_info"]);
	$g_show["tuijian_user_detail"]["province_name"] = $config['province'][$g_show["tuijian_user_detail"]["province"]]["name"];
	$g_show["tuijian_user_detail"]["city_name"] = $config['city'][$g_show["tuijian_user_detail"]["province"]][$g_show["tuijian_user_detail"]["city"]];
	$g_show["tuijian_user_detail"]["main_topic"] = $config['site_name'][$g_show["tuijian_user_detail"]["main_topic_id"]];
	$g_show["tuijian_user_detail"]["head_url"] = str_replace("/50/","/180/",$g_show["tuijian_user_detail"]["head_url"] );
	
	$mblog_cache_v2 = new mblog_cache_v2();
	$mblog_user_info = $mblog_cache_v2->cache_api_get_user_info_by_uid($g_show["tuijian_user_detail"]["openid"]);
	$g_show["mblog_user_info"] = $mblog_user_info["data"]["result"];
	
	
	$db_mblog_pic_content = new db_mblog_pic_content();
	$pic_list = $db_mblog_pic_content->get_mblog_pubu_list_by_topic(1,7,"",$g_show["tuijian_user_detail"]["uid"]);
	foreach($pic_list as $key => $value)
	{
		$pic_list[$key]["domain_url"] = $config["domain_url"][$value["topic_id"]];
		$pic_list[$key]["pic"] =  str_replace("/bmiddle/","/thumb300/",$pic_list[$key]["pic"]);
		$pic_list[$key]["content_short"] =  string_utf8::substr_utf8_cn_v2($pic_list[$key]["content"],156);
	}
	
	$g_show['pic_list'] = $pic_list;
	
	
	
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	$smarty->display("tuijian/user.html");
	
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

